package com.msb.userclient.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

/**
 * @author DreamAndLove
 * @date 2024/09/06 15:26
 * @description
 */
@Service
public class UserService {
    @Autowired
    RestTemplate restTemplate;

    /**
     * 功能:restTemplate的Hystrix的降级实现
     * 为了让restTemplate的降级方法生效，在主类上添加了@EnableCircuitBreaker注解
     * @author DreamAndLove
     * @return String
     * @date 2024/9/6 15:29
     */
    @HystrixCommand(defaultFallback = "timeoutTestFallback")
    public String timeoutTest() {
        String url = "http://user-provider/timeoutTest";
        String forObject = restTemplate.getForObject(url, String.class);

        return forObject;
    }

    public String timeoutTestFallback(){
        return "restTemplate的降级方法";
    }
}
